#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<stdio.h>
#include<queue>
#include<cstdlib>

using namespace std;

const int MAX = 3010;

struct Node
{
	int id;
	int period_sum;
	Node(int x, int y):id(x),period_sum(y) {}
};

int asc[MAX];

struct cmp
{
	bool operator() (Node a,Node b)
	{
		return a.period_sum > b.period_sum;
	}
};

struct cmp1
{
	bool operator() (int a, int b)
	{
		return a > b;
	}
};

int main()
{
	priority_queue<Node,vector<Node>,cmp> pq;
	priority_queue<int,vector<int>,cmp1> pq1;
	string str;
	int x,k;
	int y;
	while(cin>>str)
	{
		if(str=="#")
			break;
		cin>>x>>y;
		asc[x] = y;
		pq.push( Node(x,y) );
	}
	
	cin>>k;
	while(k>0)
	{
		Node node = pq.top();
		pq.pop();
		int tmp = node.period_sum;
		node.period_sum += asc[ node.id ];
		pq.push(node);
		pq1.push( node.id );
		while( pq.top().period_sum == tmp )
		{
			node = pq.top();
			pq.pop();
			node.period_sum += asc[ node.id ];
			pq.push( node );
			pq1.push( node.id );
		}

		while(!pq1.empty())
		{
			if(k==0)
				break;
			cout<<pq1.top()<<endl;
			pq1.pop();
			k--;
		}
	}//for

    system("pause") ;
	return 0;

}

